﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OABLL;
using OAModel;

namespace MyOA
{
   
    public partial class LiZhiXinXi : Form
    {
        
        LiZhiBLL bll = new LiZhiBLL();
        public string _yuangongid = string.Empty;
      
        public LiZhiXinXi(string oa)
        {
            InitializeComponent();
            this._yuangongid = oa;
          


        }


        private void LiZhiXinXi_Load(object sender, EventArgs e)
        {
            ZhuanzhengEntity user = new ZhuanZhengBLL().Getzhuanzheng(_yuangongid);
            this.lbl员工姓名.Text = user.Oa员工姓名;
            this.lbl员工id.Text = user.Oa员工id;
        }
        private void btn离职提交_Click(object sender, EventArgs e)
        {
                Random rad = new Random();
                LizhiEntity lz = new LizhiEntity();
                lz.Oa员工id = lbl员工id.Text.Trim();
                lz.Oa员工姓名 = lbl员工姓名.Text.Trim();
                lz.Oa离职内容 = tx离职内容.Text.Trim(); 
                lz.Oa离职单号 = rad.Next(10000, 9999999).ToString();
                bool b1 = bll.AddUserLiZhi(lz);
            if (b1 == true)
            {
                MessageBox.Show("提交申请成功，等待审批中！");

            }
            else
            {
                MessageBox.Show("提交失败，请稍后重试！");
            }

            List<LizhiEntity> list = new List<LizhiEntity>();
            list = bll.Addnewlizhi(_yuangongid);
            listView1.Items.Clear();
            for (int i = 0; i < list.Count; i++)
            {
                LizhiEntity user = list[i];
                ListViewItem item = new ListViewItem();
                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
                
                item.SubItems.Add(user.Oa离职内容);
                item.SubItems.Add(user.Oa离职时间);

                item.SubItems.Add(user.Oa离职单号);
                string str = "";
                if (user.Oa状态.ToString() == "0")
                {

                    str = "待审核";
                }
                else if (user.Oa状态.ToString() == "1")
                {
                    str = "审核通过";
                }
                else
                {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);
                this.listView1.Items.Add(item);
            }



        }



        private void lk离职查看_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string key = this.lbl员工id.Text.Trim();
            List<LizhiEntity> list = bll.Getneirong(key);
            this.listView1.Items.Clear();
            for (int i = 0; i < list.Count; i++)
            {
                LizhiEntity user = list[i];

                ListViewItem item = new ListViewItem();
                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
                item.SubItems.Add(user.Oa离职内容);
                item.SubItems.Add(user.Oa离职时间);
                item.SubItems.Add(user.Oa离职单号);
                string str = "";
                if (user.Oa状态.ToString() == "0")
                {

                    str = "待审核";
                }
                else if (user.Oa状态.ToString() == "1")
                {
                    str = "审核通过";
                }
                else
                {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);
                this.listView1.Items.Add(item);
            }
        }

        private void 删除申请ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                string 离职单号 = this.listView1.SelectedItems[0].SubItems[4].Text;
                if (bll.RemoveBydanhao(离职单号)) 
                {
                    foreach (ListViewItem item in this.listView1.SelectedItems) {

                        this.listView1.Items.RemoveAt(item.Index);
                    }

                    
                }
                
            }

        }

        private void 修改申请ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string 离职单号 = this.listView1.SelectedItems[0].SubItems[3].Text.Trim();
          
        }

        private void LiZhiXinXi_Load_1(object sender, EventArgs e)
        {

            OAUseEntity user = new OAUseBLL().Getyuangong(_yuangongid);
            this.lbl员工id.Text = user.Oa员工id;
            this.lbl员工姓名.Text = user.Oa姓名;

        }
    }
}
